﻿using System;
using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Web.DynamicData;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RMS.Admin
{
    public partial class Boolean_EditField : System.Web.DynamicData.FieldTemplateUserControl
    {
        ListItem itemone;
        ListItem itemtwo;
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);
            itemone = new ListItem();
            itemtwo = new ListItem();
            getText();

            object val = FieldValue;
            if (val != null)
                if ((bool)val)
                    itemone.Selected = true;
                else
                    itemtwo.Selected = true;

            RadioButtonList1.Items.Add(itemone);
            RadioButtonList1.Items.Add(itemtwo);

        }
        protected override void ExtractValues(IOrderedDictionary dictionary)
        {
            if (RadioButtonList1.SelectedIndex == 0)
                dictionary[Column.Name] = true;
            else
                dictionary[Column.Name] = false;
        }

        public override Control DataControl
        {
            get
            {
                return RadioButtonList1;
            }
        }
        private void getText()
        {
            if (this.Column.Name.ToLower().Equals("gender") || this.Column.Name.ToLower().Equals("patientgander"))
            {
                itemone.Text = "Male";
                itemone.Selected = true;
                itemtwo.Text = "Female";
            }
            if (this.Column.Name.ToLower().Equals("isactive"))
            {
                itemone.Text = "Yes";
                itemtwo.Text = "No";
                itemtwo.Selected = true;
            }
            if (this.Column.Name.ToLower().Equals("patientsituation"))
            {
                itemone.Text = "Out Patient";
                itemone.Selected = true;
                itemtwo.Text = "IN Patient";
            }
            if (this.Column.Name.ToLower().Equals("requeststatues"))
            {
                itemone.Text = "Done";
                itemtwo.Text = "Not Yet";
                itemtwo.Selected = true;
            }

        }


    }
}
